<template>
	<view class="scroll-view-container">
		<!-- 左侧的滑动 -->
		<scroll-view scroll-y="true" :style="{height: windowHeight+'px'}" class="left-scroll-view">
			<block v-for="(item,idx) in cateList" :key="idx">
				<!-- <view  class="left-scroll-view-item" :class="{active:active===idx}" @click="activeChange(idx)">{{ item.cat_name}}</view> -->
				<!-- <view  :class="{active:active===idx,'left-scroll-view-item':true}" @click="activeChange(idx)">{{ item.cat_name}}</view> -->
				<view  :class="['left-scroll-view-item',active===idx?'active':'']" @click="activeChange(idx)">{{ item.cat_name}}</view>
			</block>
		</scroll-view>
		
		<scroll-view scroll-y="true" :style="{height: windowHeight+'px'}" :scroll-top="scrollTop">
				<view v-for="(item,idx) in cateLevel2" :key="idx" class="cate-lv2">
					<!-- 二级分类标题 -->
					<view class="cate-lv2-title"> {{ item.cat_name }}</view>
					<!-- 三级分类 -->
					<view class="cate-lv3-list">
						<view class="cate-lv3-item" v-for="(item3,idx3) in item.children" :key="idx3" @click="gotoGoodsList(item3)">
							<image :src="item3.cat_icon" ></image>
							<text> {{ item3.cat_name }}</text>
						</view>
					</view>
				</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
		scrollTop:0,// 滚动高度
				cateLevel2:[],// 二级分类
				active:0,// 当前激活
				windowHeight:0,// 当前设备可用高度
				cateList:[]
			};
		},
		onLoad() {
			// 获取屏幕高度
			const sysInfo = uni.getSystemInfoSync()
			this.windowHeight = sysInfo.windowHeight
			this.getCateList()
		},
		methods:{
			gotoGoodsList(item3){
				uni.navigateTo({
					url:"/subpkg/goods_list/goods_list?cid="+item3.cat_id
				})
			},
			activeChange(idx){
				this.active =idx
				
				this.cateLevel2  = this.cateList[idx].children
				this.scrollTop = this.scrollTop===0?1:0
			},
		async	getCateList(){
				const {data:res} =await uni.$http.get("/api/public/v1/categories")
				if(res.meta.status !==200){
					return uni.showMsg()
				}
				console.log(res,"res")
				this.cateList = res.message
				
				this.cateLevel2 = res.message[0].children
			}
		}
	}
</script>

<style lang="scss">
.scroll-view-container{
	display: flex;
	.left-scroll-view{
		width: 120px;
		.left-scroll-view-item{
			background: #f7f7f7;
			line-height: 60px;
			text-align: center;
			font-size: 12px;
			box-sizing: border-box;
			border: 1px solid red;
			
			&.active{
				background-color: #fff;
				position: relative;
				
				&::before{
					content: "";
					display: block;
					width: 3px;
					height: 30px;
					background-color: red;
					position: absolute;
					top: 15px;
				}
			}
		}
		
	}

}

.cate-lv2-title{
	font-size: 12px;
	font-weight: bold;
	text-align: center;
	padding: 15px 0;
}

.cate-lv3-list{
	display: flex;
	flex-wrap: wrap;
	.cate-lv3-item{
		width: 33.33%;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		margin-bottom: 10px;
		image{
			width: 60px;
			height: 60px;
		}
		text{
			font-size: 12px;
		}
	}
}

</style>
